package lc.二叉树;

import utils.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/13
 */
public class Math257_二叉树的所有路径 {

    public List<String> binaryTreePaths(TreeNode root) {

        List<String> res = new ArrayList<>();
        dfs(root,"", res);
        return res;

    }

    private void dfs(TreeNode root, String path, List<String> res) {

        if (root == null) return;
        if (root.left == null && root.right == null) {
            res.add(path + root.val);
            return;
        }
        dfs(root.left,path + root.val + "->",res);
        dfs(root.right,path + root.val + "->",res);
    }
}
